package com.github.shiqiyue.learn.guava;

import com.google.common.primitives.Longs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/***
 * Longs测试
 * @author wenyao.wu
 * @date 2018/7/3
 */
public class LongsTest {

    private static final Logger logger = LoggerFactory.getLogger(LongsTest.class);

    public static void main(String[] args) {

        long[] longArray = {1, 2, 3, 4, 5, 6, 7, 8, 9};

        //convert array of primitives to array of objects
        List<Long> objectArray = Longs.asList(longArray);
        logger.info("{}", objectArray);

        //convert array of objects to array of primitives
        longArray = Longs.toArray(objectArray);

        logger.info("{}", longArray);
        //check if element is present in the list of primitives or not
        logger.info("5 is in list? {}", Longs.contains(longArray, 5));

        //Returns the minimum
        logger.info("Min: {}", Longs.min(longArray));

        //Returns the maximum
        logger.info("Max: {}", Longs.max(longArray));

        //get the byte array from an integer
        byte[] byteArray = Longs.toByteArray(257);
        logger.info("{}", byteArray);
    }
}
